package wps.component.elementsetting {

import flash.geom.Point;

import wps.skin.SettingHSliderSkin;

/**
 * 代码从spark.components.HSlider复制，继承SettingSliderBase
 */
public class SettingHSlider extends SettingSliderBase {

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function SettingHSlider() {
        super();

        setStyle("skinClass", Class(SettingHSliderSkin));
    }

    //--------------------------------------------------------------------------
    //
    // Methods
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    override protected function pointToValue(x:Number, y:Number):Number {
        if (!thumb || !track)
            return 0;

        var range:Number = maximum - minimum;
        var thumbRange:Number = track.getLayoutBoundsWidth() - thumb.getLayoutBoundsWidth();
        return minimum + ((thumbRange != 0) ? (x / thumbRange) * range : 0);
    }

    /**
     *  @private
     */
    override protected function updateSkinDisplayList():void {
        if (!thumb || !track)
            return;

        var thumbRange:Number = track.getLayoutBoundsWidth() - thumb.getLayoutBoundsWidth();
        var range:Number = maximum - minimum;

        // calculate new thumb position.
        var thumbPosTrackX:Number = (range > 0) ? ((pendingValue - minimum) / range) * thumbRange : 0;

        // convert to parent's coordinates.
        var thumbPos:Point = track.localToGlobal(new Point(thumbPosTrackX, 0));
        var thumbPosParentX:Number = thumb.parent.globalToLocal(thumbPos).x;

        thumb.setLayoutBoundsPosition(Math.round(thumbPosParentX), thumb.getLayoutBoundsY());
    }

}

}
